var rankData = require('./rankData')();
var GameData = require('../../module/GameData')();

cc.Class({
    extends: cc.Component,

    properties: {
        rank_list: cc.ScrollView,
        rankItem: cc.Prefab,
        rank_left_list: cc.ToggleContainer,
        rank_toggle: cc.Prefab,
        myrank: cc.Node,
        introduction_node:cc.Node,
        title: cc.Label,
        dsc: cc.Label,

    },

    // LIFE-CYCLE CALLBACKS:
    onEnable() {
        this.rankId = 0;
        this.selecthero_List(0);
    },
    onLoad() {
        GameData.rank = this;
        this.rank_pool = new cc.NodePool();
        this.rankItemArr = [];
        this.content = this.rank_list.content;
        this.initToglle();

        var fun=function(){};
        cc.find("loadbg").getComponent("loadbg").show(fun)

    },
    /** 对榜单上的信息进行处理
     * time 2019/8/26
     * author:zzw
     * dsc:
     */
    clear_Rank_list() {
        if (this.rankItemArr.length > 0) {
            for (var a = 0; a < this.rankItemArr.length; a++) {
                this.rank_pool.put(this.rankItemArr[a]);
                this.rankItemArr.splice(a, 1);
                a--;
            }
        }
    },
    /** 初始化榜单
     * time 2019/8/26
     * author:zzw
     * dsc:
     */
    initrank(_rankArr) {
        this.clear_Rank_list();
        var rankArr=_rankArr[0];
        for (var a = 0; a < rankArr.length; a++) {
            var item;
            if (this.rank_pool.size() > 0) {
                item = this.rank_pool.get();
            } else {
                item = cc.instantiate(this.rankItem);
            }
            this.rankItemArr.push(item);
            item.getComponent('rank_item').init(rankArr[a]);
            this.content.addChild(item);
        }
        this.myrank.getComponent("rank_item").init(_rankArr[1][0]);
        this.content.position = cc.v2(0, 195);
    },
    selecthero_List(id) {
        this.rankId = id;
        var rankArr = rankData.rank_data[id];
        this.initrank(rankArr);
    },
    /** 初始化分类列表
     * time 2019/8/26
     * author:zzw
     * dsc:
     */
    initToglle() {
        var data = rankData.rank_toggleData;
        for (var a = 0; a < data.length; a++) {
            var item = cc.instantiate(this.rank_toggle);
            item.getComponent("rank_toggle").init(data[a]);
            item.parent = this.rank_left_list.node;
        }
    },
    /** 实现 不同按钮对应不同榜单
     * time 2019/8/26
     * author:zzw
     * dsc:
     */
    select_rank(id) {
        if (id !== this.rankId) {
            this.selecthero_List(id);
        }
    },

    /** 对自己的榜单进行处理
     * time 2019/8/26
     * author:zzw
     * dsc:
     */
    initMyselfRank(){

    },


    /** 排行榜介绍
     * time 2019/8/26
     * author:zzw
     * dsc:
     */
    init_introduction() {
        this.title.string = rankData.rank_title;
        this.dsc.string = rankData.rank_dsc;
    },

    selectBtn(evt) {
        let _name = evt.currentTarget.name;
        switch (_name) {
            case "tip":
                this.introduction_node.active=true;
                this.init_introduction();
                break;
            case "back":
                cc.director.loadScene("game_start");
                break;
            case "close":
                this.introduction_node.active=false;
                break;


        }
    },


    // update (dt) {},
});
